var $content;

function triggerRegisterForm(){
	$("#btInscription").click(function(e){
		e.preventDefault();

		$.mobile.showPageLoadingMsg();

		var pseudo = $('input[name*="pseudo"]').val();
		var email = $('input[name*="email"]').val();
		var mdp = $('input[name*="mdp"]').val();

		addNewUser(pseudo, email, mdp);

	})
}

function addNewUser(pseudo, email, mdp){
	var dataUser = 
		{
		   "name":pseudo,	
		   "mail":email,
		   "pass":mdp
		};

	$.ajax ({
		data: dataUser,
		type: 'post',
		dataType: "json",
		url : "http://vlove.helia-agency.com/vloveur/user/register.json",
		success: function(result){
			console.log(result);

			localStorage.setItem("uid", result.uid);
			alert("Votre compte a bien été créée");

			$.mobile.changePage( "map.html" );

			$.mobile.hidePageLoadingMsg();

		},
		error : function (XMLHttpRequest, textStatus, errorThrown){
			$('p.error').html(errorThrown).show();

			$.mobile.hidePageLoadingMsg();
		}
	});
}

$("#inscription").on("pageshow", function (event) {
	$('.menu').load('menu.html',function(){ $('#menu').panel(); });

	triggerRegisterForm();
});